package de.cketti.mailto.sample;

import de.cketti.mailto.EmailIntentBuilder;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.aafwk.content.Intent;
import ohos.app.Context;
import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

public class ExampleOhosTest {

    private Context context;
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("de.cketti.mailto.sample", actualBundleName);
    }


    @SuppressWarnings("ConstantConditions")
    @Test(expected = IllegalArgumentException.class)
    public void to_withNullArgument_shouldThrow() {
        EmailIntentBuilder.from(context)
                .to((String) null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void to_withArgumentStartingWithAt_shouldThrow() {
        EmailIntentBuilder.from(context)
                .to("@example.org");
    }

    @Test(expected = IllegalArgumentException.class)
    public void to_withArgumentEndingInAt_shouldThrow() {
        EmailIntentBuilder.from(context)
                .to("hi@");
    }

    @Test(expected = IllegalArgumentException.class)
    public void to_withArgumentNotContainingAt_shouldThrow() {
        EmailIntentBuilder.from(context)
                .to("bob(at)example.org");
    }

    @SuppressWarnings("ConstantConditions")
    @Test(expected = IllegalArgumentException.class)
    public void subject_withNullArgument_shouldThrow() {
        EmailIntentBuilder.from(context)
                .subject(null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void subject_withArgumentContainingCarriageReturn_shouldThrow() {
        EmailIntentBuilder.from(context)
                .subject("This is an important\rsubject");
    }

    @Test(expected = IllegalArgumentException.class)
    public void subject_withArgumentContainingLineFeed_shouldThrow() {
        EmailIntentBuilder.from(context)
                .subject("Keep\nreading");
    }

    @Test(expected = IllegalArgumentException.class)
    public void subject_withArgumentContainingCrLf_shouldThrow() {
        EmailIntentBuilder.from(context)
                .subject("One\r\nTwo");
    }


}